package work.chenbo.zmqc.business.channe.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import work.chenbo.zmqc.business.channe.dao.mongo.ChannelGlobalRuleMongo;
import work.chenbo.zmqc.business.channe.model.ChannelGlobalRuleVO;

/**
 * @author ChenBo
 * @className ChannelGlobalRuleController
 * @date 2020/11/9
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/channel/rule/")
@Api(value = "globalRule",tags = {"全局规则接口"})
public class ChannelGlobalRuleController {

    private final ChannelGlobalRuleMongo channelGlobalRuleMongo;


    @PostMapping(value = "/save",produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加全局规则",notes = "第一次创建全局规则",produces = MediaType.APPLICATION_JSON_VALUE,
            response = ChannelGlobalRuleVO.class)
    public Object saveGlobalRule(@RequestBody ChannelGlobalRuleVO channelGlobalRuleVO){
        ChannelGlobalRuleVO save = channelGlobalRuleMongo.save(channelGlobalRuleVO);
        return save;
    }


    @GetMapping("/get/{ruleId}")
    @ApiOperation(value = "获取全局规则配置",notes = "通过规则ID获取全局配置",response = ChannelGlobalRuleVO.class)
    public Object getGlobalRuleByRuleId(@PathVariable("ruleId") Integer ruleId){
        ChannelGlobalRuleVO byRoleId = channelGlobalRuleMongo.findByRoleId(ruleId);
        return byRoleId;
    }

}
